package cn.pupil.design;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 银行卡
 * @Author: pupil
 * @Date: 2024/06/23 下午 10:46
 */
public abstract class BankCard {

    private Logger logger = LoggerFactory.getLogger(BankCard.class);
    private static List<String> tradeList = new ArrayList<String>();

    private String cardId;   // 卡号
    private String cardDate; // 开卡时间

    public BankCard(String cardId, String cardDate) {
        this.cardId = cardId;
        this.cardDate = cardDate;
    }

    abstract boolean rule(BigDecimal amount);


    /**
     * 正向入账，+ 钱
     * @param orderId 单号
     * @param amount 金额
     * @return 状态码 0000成功、0001失败、0002重复
     */
    public String positive(String orderId, BigDecimal amount) {
        // 入款成功，存款、还款
        logger.info("卡号{} 入款成功，单号：{} 金额：{}", cardId, orderId, amount);
        return "0000";
    }

    /**
     * 逆向入账，- 钱
     * @param orderId
     * @param amount
     * @return 状态码 0000成功、0001失败、0002重复
     */
    public String negative(String orderId, BigDecimal amount) {
        // 入款成功，存款、还款
        logger.info("卡号{} 出款成功，单号：{} 金额：{}", cardId, orderId, amount);
        return "0000";
    }

    /**
     * 交易流水查询
     *
     * @return 交易流水
     */
    public List<String> tradeFlow() {
        logger.info("交易流水查询成功");
        tradeList.add("14451,100.00");
        tradeList.add("14451,80.00");
        tradeList.add("14451,76.50");
        tradeList.add("14451,126.00");
        return tradeList;
    }

    public String getCardId() {
        return cardId;
    }

    public String getCardDate() {
        return cardDate;
    }
}
